package com.wanhelibs.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.wanhe.base.model.base.Dish;
import com.wanhelibs.R;

import java.util.List;

/**
 * Created by XieZaiWei on 2017/8/10.
 * 换菜Dialog Adapter
 */

public class ChangeSetMealAdapter extends BaseAdapter {
	private LayoutInflater mInflater;
	private List<Dish> mArrDish;

	public ChangeSetMealAdapter(Context context, List <Dish> arrDish) {
		mInflater = LayoutInflater.from(context);
		mArrDish = arrDish;
	}

	@Override
	public int getCount() {
		if (mArrDish != null) {
			return mArrDish.size();
		} else {
			return 0;
		}

	}

	@Override
	public Dish getItem(int position) {
		return mArrDish.get(position);
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		ViewHolder viewHolder;
		if (convertView == null) {
			viewHolder = new ViewHolder();
			convertView = mInflater.inflate(R.layout.change_set_meal_item, null);
			viewHolder.tv_name = (TextView) convertView.findViewById(R.id.tv_name);
			viewHolder.tv_select = (TextView) convertView.findViewById(R.id.tv_select);
			convertView.setTag(viewHolder);

		} else {
			viewHolder = (ViewHolder) convertView.getTag();
		}

		Dish dish = mArrDish.get(position);
		viewHolder.tv_name.setText(dish.getVch_dishname());
		if(dish.isChose){
			viewHolder.tv_select.setText("选择");
		}else {
			viewHolder.tv_select.setText("");
		}
		return convertView;
	}

	private static class ViewHolder {
		public TextView		tv_name;
		public TextView		tv_select;
	}
}
